﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hsinchu.Model;
using Hsinchu.BLL;

public partial class Admin_BasicSetup_UserManager : System.Web.UI.Page
{
    Hsinchu.BLL.AdminManager dllAdminManager = new AdminManager();
    Hsinchu.BLL.AdminGroup dllAdminGroup = new AdminGroup();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitLoad();
        }
    }


    /// <summary>
    /// 初始化载入
    /// </summary>
    void InitLoad()
    {
        LoadComboxUserGroup();
        LoadGridViewAdmin();
    }


    /// <summary>
    /// 载入后台用户组
    /// </summary>
    void LoadComboxUserGroup()
    {
        this.comboxUserGroup.DataSource = dllAdminGroup.GetUserGroup();
        this.comboxUserGroup.TextField = "GroupName";
        this.comboxUserGroup.ValueField = "GroupId";
        this.comboxUserGroup.DataBind();
        this.comboxUserGroup.SelectedIndex = 0;
    }


    /// <summary>
    /// 载入后台用户
    /// </summary>
    void LoadGridViewAdmin()
    {
        this.gdvUser.DataSource = dllAdminManager.GetMAdmin();
        this.gdvUser.DataBind();
    }


    /// <summary>
    /// 添加后台用户
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MAdmin Admin = new MAdmin();
        Admin.Name = this.txtUserName.Text;
        Admin.GroupId = Convert.ToInt32(this.comboxUserGroup.SelectedItem.Value);
        Admin.PassWord = this.txtUserPassWord.Text;
        if (dllAdminManager.AddAdminUser(Admin) > 0)
        {
            //弹出对话框提示
        }
    }
}
